﻿using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour {

	public ActorController me;
	public ActorController player;

	private int xVelocity;
	private int zVelocity;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

		if (transform.position.x < player.transform.position.x)
			xVelocity++;

		if (transform.position.x > player.transform.position.x)
			xVelocity--;

		if (transform.position.z < player.transform.position.z)
			zVelocity++;

		if (transform.position.z > player.transform.position.z)
			zVelocity--;
		
		if (xVelocity < -6)
			xVelocity = -6;
		
		if (xVelocity > 6)
			xVelocity = 6;

		if (zVelocity < -6)
			zVelocity = -6;

		if (zVelocity > 6)
			zVelocity = 6;
		
		//if (xVelocity < 0 && transform.position.z - xVelocity > player.transform.position.z)
		//	xVelocity = 0;
		
		//if (xVelocity > 0 && transform.position.z - zVelocity < player.transform.position.z)
		//	xVelocity = 0;

		//if (zVelocity < 0 && transform.position.z - zVelocity > player.transform.position.z)
		//	zVelocity = 0;

		//if (zVelocity > 0 && transform.position.z - zVelocity < player.transform.position.z)
		//	zVelocity = 0;

		me.Move (new Vector3 (xVelocity, 0, zVelocity));
	}
}
